﻿using FluentAssertions;
using RandomKatas.Kata06;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;

namespace RandomKataTests
{
    [TestClass]
    public class AnagramsTest
    {
        [TestMethod]
        public void SmallWordlist()
        {
            var wordlist = new[] { "brap", "pabr", "foo", "oof", "bilbo" };
            var result = new Anagrams().FindAnagrams(wordlist);
            result.Should().Contain(x => new HashSet<string>(new[] { "brap", "pabr" }).SequenceEqual(x));
            result.Should().Contain(x => new HashSet<string>(new[] { "foo", "oof" }).SequenceEqual(x));
            result.Should().NotContain(x => x.Contains("bilbo"));
        }

        [TestMethod]
        public void LargeWordlist()
        {
            var result = new Anagrams().FindAnagrams(Properties.Resources.WordList.Split().Select(x => x.Trim()));
            var maxSize = 0;
            List<string> best = null;
            foreach (var list in result)
            {
                list.ForEach(x => x.Length.Should().Be(list[0].Length, 
                    "because {0} should be same length: {1}", x, string.Join(", ", list)));
                if (maxSize < list[0].Length)
                {
                    maxSize = list[0].Length;
                    best = list;
                }
                if (list[0].Length > 4)
                    Trace.TraceInformation("{0}: {1}", list.Count, string.Join(", ", list));
            }

            Trace.TraceInformation("{0} ({1}) is max size anagram of {2}", maxSize, string.Join(", ", best), result.Count());
        }
    }
}
